﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Business.Models;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.ProjectCategoryHandler
{
    public class GetCategoryById
    {
        private readonly ProjectCategoryRepository _projectCategoryRepository;

        public GetCategoryById()
        {
            _projectCategoryRepository = new ProjectCategoryRepository();
        }
        public GetCategoryById(ProjectCategoryRepository projectCategoryRepository)
        {
            _projectCategoryRepository = projectCategoryRepository;
        }

        public virtual ProjectCategoryModel Execute(int? projectId, int? categoryId)
        {
            ProjectCategoryModel projectCategoriesModel = null;

            try
            {
                // try to get from db
                project_categories projectCategoriesData =
                    _projectCategoryRepository.GetProjectCategory(projectId, categoryId);

                // parse to business model
                if (projectCategoriesData != null)
                {
                    projectCategoriesModel = new ProjectCategoryModel(projectCategoriesData);
                }

                return projectCategoriesModel;
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
                return null;
            }
        }
    }
}
